package cn.wbnull.springbootdemo.controller;

import cn.wbnull.springbootdemo.service.WebSocketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.WebSocketSession;

@Controller
public class ChatController {

    @Autowired
    private WebSocketService webSocketService;

    @PostMapping("/Connection")
    public void Connection(WebSocketSession message) {
        webSocketService.Connection(message);
        System.out.println("收到消息：" + message);
    }

    @PostMapping("/DisConnection")
    public void DisConnection(WebSocketSession message, CloseStatus status) {
        webSocketService.Close(message,status);
        System.out.println("收到消息：" + message);
    }
}